package com.bwie.service.impl;

import cn.hutool.core.io.file.FileNameUtil;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.bwie.pojo.TbInfo;
import com.bwie.service.TbInfoService;
import com.bwie.mapper.TbInfoMapper;
import com.bwie.utils.R;
import com.github.tobato.fastdfs.domain.StorePath;
import com.github.tobato.fastdfs.service.FastFileStorageClient;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.web.multipart.MultipartFile;

import java.io.IOException;
import java.util.List;

/**
* @author 叶雨洁
* @description 针对表【tb_info】的数据库操作Service实现
* @createDate 2025-07-15 11:53:55
*/
@Service
public class TbInfoServiceImpl extends ServiceImpl<TbInfoMapper, TbInfo>
    implements TbInfoService{

    @Autowired
    TbInfoMapper infoMapper;

    @Autowired
    FastFileStorageClient fastFileStorageClient;

    @Override
    public R getEatList() {
        List<TbInfo> tbInfos = infoMapper.selectList(null);
        return R.OK(tbInfos);
    }

    @Override
    public R uploadImage(MultipartFile file) {

        try {
            String extName = FileNameUtil.extName(file.getOriginalFilename());

            StorePath storePath = fastFileStorageClient.uploadFile(file.getInputStream(), file.getSize(), extName, null);

            String url="http://192.168.80.192:8888"+storePath.getFullPath();
            return R.OK(url);

        } catch (IOException e) {
            e.printStackTrace();
            return R.ERROR(500,"上传失败");
        }

    }
}




